<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redirect;

class AuthCheck
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if($request->isMethod('get')){
            //检测是否已登录
            if(Auth('admin')->check()){
                return Redirect::route('admin.index')->send();
            }else{
                return $next($request);
                return redirect('/admin/login');
            }
        }else{
            return $next($request);
        }
    }
}
